/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.myapp.struts.dao;

import com.myapp.struts.prepare.PrepareMenu;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author pavan
 */
public class MenuDao {

    private Connect mysql;
    private Connection con;
    private String privlage_name;
    private PreparedStatement pstmt;
    private ResultSet getPrivlages;
    private PrepareMenu pmenu;
    private Vector vec;

    public MenuDao() {
        pmenu = new PrepareMenu();
        vec = new Vector();
    }

    public Connection getConnection() throws Exception {
        mysql = new Connect();
        con = mysql.mySql();
        return con;
    }

    public Vector getItems(String role, String priv_type) {
        try {
            con = getConnection();
            vec = new Vector();
            System.out.println("Ur Role is " + role);
            System.out.println("Ur priv_type is " + priv_type);
            privlage_name =
                    " SELECT p.priv_name,p.priv_path FROM user_privilages p,user_roles r " + " where r.role_name='" + role + "' and r.role_name=p.role_name " +
                    "and p.priv_type='" + priv_type + "'";
            System.out.println("que" + privlage_name);
            pstmt = con.prepareStatement(privlage_name);
            //pstmt.setString(1,role);
            //pstmt.setString(2,priv_type);
            getPrivlages = pstmt.executeQuery();
            vec = pmenu.prepareMenuList(getPrivlages);
            System.out.println("Vec" + vec.size());
            getPrivlages.close();
            pstmt.close();
            con.close();
            System.out.println("Close in items");
        } catch (Exception ex) {
            Logger.getLogger(MenuDao.class.getName()).log(Level.SEVERE, null, ex);
        }
        return vec;
    }
}
